package com.zp.demo.repush.service.impl;

import com.zp.demo.repush.enums.RePushType;
import com.zp.demo.repush.service.defined.*;
import com.zp.demo.repush.vo.BaseRePushVo;
import com.zp.demo.repush.vo.RePushStrategyEntity;
import com.zp.demo.service.impl.ScheduledTestServie;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @Author 张鹏
 * @Date 2019/1/2 12:36
 */
@Log4j2
public class BaseRePushServiceImpl implements DefindRePushDbService,DefindSendEmailService,DefindSaveLogService,DefindSendEmsService {

    @Autowired
    private ScheduledTestServie scheduledTestServie;
    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;


    @Override
    public BaseRePushVo callbackRepush(BaseRePushVo pushVo, boolean result, Integer remainingCounts,RePushType pushType,String mess) {
        log.debug(pushType.getDesc() + "任务回调：-------------剩余重推次数${remainingCounts}--------------", remainingCounts);
        if (result) {
            log.info("-----------------及时任务：重新调用成功了-------------------");
        }
        switch (pushType) {
            case JS_PUSH:
                break;
            case YS_PUSH:
                log.info("加入定时" + remainingCounts);
                // todo:测试
                List<BaseRePushVo> list = new ArrayList<>();
                list.add(pushVo);
                scheduledTestServie.add2ScheduledQueue(list, redisTemplate);
                break;
            case DS_PUSH:
                break;
            default:
                break;
        }

        return pushVo;
    }

    @Override
    public BaseRePushVo saveRepush2DB(BaseRePushVo pushVo, RePushStrategyEntity strategyEntity) {
        return null;
    }

    @Override
    public void save2DbScheduledJob(BaseRePushVo pushVo, Integer counts) {
        log.info("添加到定时任务未添加");
    }

    @Override
    public boolean saveLog(BaseRePushVo pushVo) {
        log.debug("未定义保存日志的方法");
        return false;
    }

    @Override
    public boolean sendEmail(BaseRePushVo pushVo) {
        log.debug("未定义发送邮件的方法");
        return false;
    }

    @Override
    public boolean sendEms(BaseRePushVo pushVo) {
        return false;
    }


}
